 package com.oanda.blackberry.ui;
 
 import com.oanda.blackberry.restapi.Quote;
 import net.rim.device.api.ui.Field;
 import net.rim.device.api.ui.Graphics;
 import net.rim.device.api.ui.component.ChoiceField;
 import net.rim.device.api.ui.component.ObjectChoiceField;
 
 public class ColoredObjectChoiceField extends ObjectChoiceField
 {
   int fontColor;
   int width;
   int height;
   int titleColor = -1;
   String title;
   boolean isFocused = false;
 
   public ColoredObjectChoiceField(int color)
   {
     this.fontColor = color;
   }
 
   public ColoredObjectChoiceField(int color, String label, Object[] choices, int width, int height) {
     super(label, choices);
 
     this.fontColor = color;
     this.width = width;
     this.height = height;
   }
 
   public ColoredObjectChoiceField(int titleColor, int color, String label, Object[] choices, int width, int height)
   {
     super("", choices);
 
     this.title = label;
     this.fontColor = color;
     this.titleColor = titleColor;
     this.width = width;
     this.height = height;
   }
 
   public void paint(Graphics g) {
     if (this.titleColor == -1) {
       this.titleColor = this.fontColor;
     }
 
     g.setColor(this.titleColor);
     g.setFont(getFont());
 
     g.setColor(this.fontColor);
 
     int index = getSelectedIndex();
     if (index > -1)
     {
       Object choice = getChoice(getSelectedIndex());
       if ((choice instanceof Quote))
       {
         if (this.isFocused) {
           g.setColor(2382517);
           g.setGlobalAlpha(240);
           g.fillRoundRect(6, 2, getWidth() - 6, getHeight() - 2, 3, 3);
           g.setGlobalAlpha(255);
         }
 
         g.setColor(this.titleColor);
         g.drawText(((Quote)choice).toString(), 8, 2);
       } else if (choice != null)
       {
         if (this.isFocused) {
           g.setColor(2382517);
           g.setGlobalAlpha(240);
           g.fillRoundRect(6, 2, 94, getHeight() - 2, 3, 3);
           g.setGlobalAlpha(255);
         }
         if (this.isFocused)
           g.setColor(16119285);
         else
           g.setColor(this.fontColor);
         g.drawText(choice.toString(), 8, 2);
       }
     }
   }
 
   public boolean isFocusable()
   {
     return true;
   }
 
   protected void layout(int maxWidth, int maxHeight)
   {
     setExtent(this.width, this.height);
   }
 
   public void setWidth(int width) {
     this.width = width;
     setExtent(width, this.height);
     invalidate();
   }
 
   public void setHeight(int height) {
     this.height = height;
   }
 
   public void setTitleColor(int titleColor) {
     this.titleColor = titleColor;
   }
 
   public void setFontColor(int fontColor) {
     this.fontColor = fontColor;
   }
 
   protected void onFocus(int direction) {
     this.isFocused = true;
 
     invalidate();
   }
 
   protected void onUnfocus() {
     this.isFocused = false;
 
     invalidate();
   }
}

